var gulp = require('gulp');
var util = require('gulp-util');
var connect = require('gulp-connect');
var os = require('os');
var open = require('gulp-open');
var webpack = require('webpack');
var gulpWebpack = require('gulp-webpack');
var webpackDevConfig = require('./webpack.dev');
var webpackDistConfig = require('./webpack.dist');
var webpackDevServer = require('webpack-dev-server');


gulp.task('dev', ['webpack-server'], function() {
  gulp.src(['app/index.html'])
    .pipe(open({
      uri: 'http://localhost:8888'
    }))
})

gulp.task('build', function() {
  gulp.src('./app/src/js/app.js')
    .pipe(gulpWebpack(webpackDistConfig))
    .pipe(gulp.dest('./app/build/'));
})

gulp.task('webpack-server', function() {
  var compiler = webpack(webpackDevConfig);
  new webpackDevServer(compiler, {
    contentBase: './app/',
    publicPath: webpackDevConfig.output.publicPath,
    hot: true,
    quiet: true,
    // historyApiFallback: true,
    noInfo: true,
    stats: {
      colors: true
    }
  }).listen(8888, 'localhost', function(err) {
    if (err) util.log(err);
  })
})